package io.hots.config;

import io.hots.exception.BizException;
import org.springframework.context.annotation.Configuration;
import io.hots.enums.BizCodeEnum;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author yueshibin@cetcbigdata.com
 * @date 2022/9/9 3:01 下午
 */
@Configuration
public class SnowFlakeWorkIdConfig {
    static {
        try {
            InetAddress ip4 = Inet4Address.getLocalHost();
            String addressIp = ip4.getHostAddress();
            System.setProperty("workerId", (Math.abs(addressIp.hashCode())%1024)+"");
        } catch (UnknownHostException e) {
            throw new BizException(BizCodeEnum.OPS_NETWORK_ADDRESS_ERROR);
        }
    }
}
